
function scalingImg(obj){
    var $this = $(obj);

    var imgWidth=obj.naturalWidth;
    var imgHeight=obj.naturalHeight;

    var parent = $this.parent();
    var containerWidth = parent.width();
    var containerHeight=parent.height();

    var containerRatio = containerWidth / containerHeight;
    var imgRatio = imgWidth / imgHeight;

    if (imgRatio > containerRatio) {
        imgWidth = containerWidth;
        imgHeight = containerWidth / imgRatio;
    } else if (imgRatio < containerRatio) {
        imgHeight = containerHeight;
        imgWidth = containerHeight * imgRatio;
    } else {
        imgWidth = containerWidth;
        imgHeight = containerHeight
	}
    $this.css("height",imgHeight);
    $this.css("width",imgWidth);
    
}
